package com.bana.fvs.app.mvp.presenter;

import android.app.Activity;

import com.bana.fvs.app.module.detaile.entity.UpdateWorkModeResultBean;
import com.bana.fvs.app.module.detaile.entity.WorkModeItemBean;
import com.bana.fvs.app.mvp.contract.WorkModeContract;
import com.bana.fvs.app.mvp.model.WorkModeModel;
import com.wei.commonlibrary.net.CommException;
import com.wei.commonlibrary.net.MyDefaultCallback;
import com.wei.commonlibrary.net.OkhttpRequest;

import java.util.List;

/**
 * Created by wei on 2018/3/3.
 */

public class WorkModePresenter extends WorkModeContract.AbsWorkModePresenter {
    @Override
    public void onStart() {

    }

    @Override
    protected WorkModeContract.AbsWorkModeModel createModel() {
        return new WorkModeModel();
    }

    @Override
    public void getWorkMode(Activity activity, String token, int type) {
        OkhttpRequest okhttpRequest;
        if (type == 1) {
            okhttpRequest = mModel.getWorkMode(token);
        } else {
            okhttpRequest = mModel.getVisiblityWorkMode(token);
        }

        okhttpRequest.callback(new MyDefaultCallback<List<WorkModeItemBean>>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView()) {
                    getView().onError(e);
                }
            }

            @Override
            public void response(List<WorkModeItemBean> list) {
                if (null != getView()) {
                    getView().getWorkMode(list);
                }
            }
        });
    }

    @Override
    public void http_WorkModeUpdate(Activity activity, String token, String wqbh, String gzms, int type) {
        OkhttpRequest okhttpRequest;
        if (type == 1) {
            okhttpRequest = mModel.http_WorkModeUpdate(token, wqbh, gzms);
        } else {
            okhttpRequest = mModel.http_VisiblityWorkModeUpdate(token, wqbh, gzms);
        }
        okhttpRequest.callback(new MyDefaultCallback<UpdateWorkModeResultBean>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView()) {
                    getView().onError(e);
                }
            }

            @Override
            public void response(UpdateWorkModeResultBean updateWorkModeResultBean) {
                if (null != getView()) {
                    getView().updtaeWorkMode(updateWorkModeResultBean);
                }
            }
        });
    }
}
